// JavaScript Document

function Alllive()
{
	this.init();	
}

Alllive.prototype =
{
	init : function()
	{
		var _this=this;
		_this.allliveTab();
		_this.autoScrollImg($(".allliveTag"));
		_this.loadImage();
	},
	loadImage:function()
	{
		$("img.lazy").lazyload({
			effect : "fadeIn"
		});
	},
	allliveTab:function()
	{
		$(".alllive ul li").on("click",function()
		{
			$(this).addClass("curr").siblings().removeClass("curr");
		});	
	},
	autoScrollImg:function (obj)
	{
		var	aUl         = obj.find("ul"),
			aList       = aUl.find("li"),
			aStage      = obj.find(".allliveStage"),
			aStageWidth = aStage.width(),
			aListWidth  = aList.width()+10,
			aUlWidth    = aListWidth*aList.length;
		aUl.css("width",aUlWidth+"px");
		if(aUlWidth>aStageWidth)//如果内容的宽度小于舞台的宽度，不复制元素进行滚动
		{ 
			var iNum=0;			
			$(".btnPrev,.btnNext").show();			
			$(".btnPrev").bind("click",function()
			{
				iNum--;
				if(iNum<0)
				{
					iNum=0;
				}
				aUl.stop().animate({"marginLeft":-(aListWidth)*iNum},500);
			});
			
			$(".btnNext").bind("click",function()
			{
				if(iNum>=aList.length-10)
				{
					iNum=aList.length-10;
				}
				iNum++;
				aUl.stop().animate({"marginLeft":-(aListWidth)*iNum},500);
			});
		}
		else
		{
			$(".btnPrev,.btnNext").hide();
			$(".allliveTag").css({"width":"800px"});
		}
	}
};

$(function()
{
	new Alllive();
});
